<?php

namespace App\Http\Validate\Invoice;

use App\Http\Validate\BaseValidate;

/**
 * 开票信息验证器
 */
class Invoice extends BaseValidate
{
    //验证规则
    protected $rule = [];
    //自定义验证信息
    protected $message = [];

    public function __construct($doaction = 'add')
    {
        if ($doaction == 'add') {
            $this->rule = [
                'custom_id' => 'required',
                'company_code' => 'required',
                'company_name' => 'required',
                'category' => 'required',
                'firm_name' => 'required',
                'credit_code' => 'required',
                'firm_address' => 'required',
                'firm_phone_number' => 'required',
                'firm_bank' => 'required',
                'firm_bank_number' => 'required',
                'firm_email' => 'required|email',
            ];
            $this->message = [
                'custom_id.required' => '客户信息不能为空',
                'company_code.required' => '往来单位编码不能为空',
                'company_name.required' => '往来单位名称不能为空',
                'category.required' => '往来单位分类不能为空',
                'firm_name.required' => '公司名称不能为空',
                'credit_code.required' => '统一信用代码不能为空',
                'firm_address.required' => '公司地址不能为空',
                'firm_phone_number.required' => '公司电话不能为空',
                'firm_bank.required' => '公司开户行不能为空',
                'firm_bank_number.required' => '公司账户不能为空',
                'firm_email.required' => '公司邮箱不能为空',
                'firm_email.email' => '公司邮箱格式不正确',
            ];
        } elseif ($doaction == 'edit') {
            $this->rule = [
                'id' => 'required',
                'custom_id' => 'required',
                'company_code' => 'required',
                'company_name' => 'required',
                'category' => 'required',
                'firm_name' => 'required',
                'credit_code' => 'required',
                'firm_address' => 'required',
                'firm_phone_number' => 'required',
                'firm_bank' => 'required',
                'firm_bank_number' => 'required',
                'firm_email' => 'required|email',
            ];
            $this->message = [
                'id.required' => '开票信息不能为空',
                'custom_id.required' => '客户信息不能为空',
                'company_code.required' => '往来单位编码不能为空',
                'company_name.required' => '往来单位名称不能为空',
                'category.required' => '往来单位分类不能为空',
                'firm_name.required' => '公司名称不能为空',
                'credit_code.required' => '统一信用代码不能为空',
                'firm_address.required' => '公司地址不能为空',
                'firm_phone_number.required' => '公司电话不能为空',
                'firm_bank.required' => '公司开户行不能为空',
                'firm_bank_number.required' => '公司账户不能为空',
                'firm_email.required' => '公司邮箱不能为空',
                'firm_email.email' => '公司邮箱格式不正确',
            ];
        } elseif($doaction == 'dopostreview') {
            $this->rule = [
                'id' => 'required',
                'status' => 'required|in:2,3,4',
            ];
            $this->message = [
                'id.required' => '开票信息不能为空',
                'status.required' => '审核状态不能为空',
                'status.in' => '参数非法',
            ];
        }
    }
}
